% MIU model in the chapter 9 in the book of RBC of ABC
var w r c k h m p g lambda y;
varexo epslambda epsg;
parameters betax deltax theta A h0 gammax piex B barg D;
betax = 0.99;
deltax = 0.025;
theta = 0.36;
A = 1.72;
h0 = 0.583;
gammax = 0.95;
piex = 0.48;
B = A*log(1-h0)/h0;
barg = 1;
D = 0.01;

model;
1/c = betax*p/(c(+1)*p(+1)) + D*p/m;
1/c = -B/w;
1/c = betax/c(+1)*(r(+1)+1-deltax);
c+k+m/p = w*h+r*k(-1)+(1-deltax)*k(-1)+m(-1)/p + (g-1)*m(-1)/p;
w = (1-theta)*lambda*k^theta*h^(-theta);
r = theta*lambda*(k/h)^(theta-1);
y = lambda*k^theta*h^(1-theta);
log(g) = (1-piex)*log(barg) + piex*log(g(-1))+epsg;
m = g*m(-1);
log(lambda) = gammax*log(lambda(-1)) + epslambda;
end;

[rss,wss,css,mpss,kss,hss,yss]=findss(betax,deltax,theta,barg,B, D);

initval;
r = rss;
w = wss;
c = css;
m = 1;
k = kss;
h = hss;
y = yss;
g = 1;
lambda = 1;
p = 1;
end;

steady;
resid;

shocks;
var epsg;
stderr 0.01;
end;

stoch_simul(irf=100, order=1) k c w r h m y g p;

shocks(overwrite);
var epslambda;
stderr 0.01;
end;

stoch_simul(irf=100, order=1) k c w r h m y g p;
